package com.batchbrake.main;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Observable;
import java.util.Observer;

import javax.swing.DefaultListModel;

import org.jdesktop.swingx.JXFrame;
import org.jdesktop.swingx.JXLabel;
import org.jdesktop.swingx.JXList;
import org.jdesktop.swingx.JXPanel;

public class HandbrakeFrame extends JXFrame implements Observer {
	private JXLabel currentMovie = null;
	private JXLabel currentStatus = null;
	private JXList currentSubtitles = null;
	private DefaultListModel srtModel = null;
	
	public HandbrakeFrame() {
		this.initComponents();
	}
	
	private void initComponents() {
		JXPanel panel = new JXPanel(new BorderLayout());
		
		currentMovie = new JXLabel("Current movie: ");
		srtModel = new DefaultListModel();
		currentSubtitles = new JXList(srtModel);
		currentStatus = new JXLabel("Current status: ");
		
		panel.add(currentMovie, BorderLayout.NORTH);
		panel.add(currentSubtitles, BorderLayout.CENTER);
		panel.add(currentStatus, BorderLayout.SOUTH);
		
		this.setSize(new Dimension(300,150));
		this.setStartPosition(StartPosition.CenterInScreen);
		this.setDefaultCloseOperation(JXFrame.EXIT_ON_CLOSE);
		this.setContentPane(panel);
	}


	@Override
	public void update(Observable observable, Object obj) {
		System.out.println(this.getClass() + " update");
		if( observable instanceof BatchBrakeProc ) {
			BatchBrakeProc t = ((BatchBrakeProc)observable);
			
			if( t.queue.size() > 0 ) {
				currentMovie.setText("Current movie: " + t.queue.get(0).getInput());
				srtModel.clear();
				for( int i = 0; i < t.queue.get(0).getSubtitles().size(); i++ ) {
					srtModel.add(i, t.queue.get(0).getSubtitles().get(i));
				}
			}
			
//			currentStatus.setText("Current status: " + t.getStatus());
			currentSubtitles.repaint();
			this.pack();
			this.repaint();
		}
	}
	
}
